{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4fd294b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "###3.6函数###\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f9d32e0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    return x**2+1\n",
    "?? func\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e5acb5ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "? func"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ec692627",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "65\n"
     ]
    }
   ],
   "source": [
    "print (func(8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "52fba24a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66.61\n"
     ]
    }
   ],
   "source": [
    "print (func(8.1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "db70f9c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "__name__ == '__main__'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b5794be4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "82\n"
     ]
    }
   ],
   "source": [
    "if __name__== \"__main__\":\n",
    "    print (func(9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b94879ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "###3.7###"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b8e36494",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student:   #定义一个类 学生\n",
    "    count= 0 \n",
    "    __tax_discount_rate = 0.1\n",
    "    \n",
    "    \n",
    "    def __init__(self, name, age, sex, fee, is_married):\n",
    "        self.name = name \n",
    "        self.age = age\n",
    "        self.sex = sex\n",
    "        \n",
    "        self.fee = fee\n",
    "        self.is_married= is_married\n",
    "        \n",
    "        Student.count += 1\n",
    "        \n",
    "    def display_student (self):\n",
    "        print(\"姓名：%s , 年龄: %d, 性别: %s\" %(self.name, self.age, self.sex))\n",
    "        \n",
    "        \n",
    "    def display_fee (self):\n",
    "        print(\"%s 的学费是 %f\"  % (self.name, self))\n",
    "     \n",
    "    \n",
    "    def is_single(self):\n",
    "        if self.is_married:\n",
    "            return False\n",
    "        else:\n",
    "            return True\n",
    "        \n",
    "    def tax_return(self):\n",
    "        if self.is_married:\n",
    "            return 0\n",
    "        else:\n",
    "            return self.fee* Student.__tax_discount_rate\n",
    "        \n",
    "    def display_tax_return(self):\n",
    "        print (\"%s 的退税额度为 %f\" %(self.name, self.tax_return()))\n",
    "        \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c11f23fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "目前学生总数为2人\n"
     ]
    }
   ],
   "source": [
    "if __name__== \"__main__\":\n",
    "    student_1 = Student(\"范淼\", 29, \"男\", 5000.0, False)\n",
    "    student_2 = Student(\"刘晓龙\", 34, \"女\", 5500.0, True)\n",
    "    \n",
    "    print (\"目前学生总数为%d人\" %Student.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c45648ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：范淼 , 年龄: 29, 性别: 男\n",
      "姓名：刘晓龙 , 年龄: 34, 性别: 女\n"
     ]
    }
   ],
   "source": [
    "student_1.display_student()\n",
    "student_2.display_student()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f7eed5db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "目前学生总数为4人\n"
     ]
    }
   ],
   "source": [
    "    student_3 = Student(\"孙华枭\", 28, \"男\", 5600, True)\n",
    "    student_4 = Student(\"陈蓓\", 27, \"女\", 4500, True)\n",
    "    print (\"目前学生总数为%d人\" %Student.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a407c2b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "陈蓓 的退税额度为 0.000000\n"
     ]
    }
   ],
   "source": [
    "student_4.display_tax_return()    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "88e71c02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "范淼 的退税额度为 500.000000\n"
     ]
    }
   ],
   "source": [
    "student_1.display_tax_return()  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "6e63b253",
   "metadata": {},
   "outputs": [],
   "source": [
    "###3.8###"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5c170560",
   "metadata": {},
   "outputs": [],
   "source": [
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0ee169d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.718281828459045"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.exp(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4467d1a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.exp(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5808f1f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from math import exp as ep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b8105253",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ep(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e2e4108a",
   "metadata": {},
   "outputs": [],
   "source": [
    "###3.9### 最后一小节### 撒花###"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8211417f",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Member:\n",
    "    count = 0 \n",
    "    \n",
    "    def __init__(self, name, score):\n",
    "        self.name = name \n",
    "        self.score = score\n",
    "        \n",
    "        if score >= 90.0:\n",
    "            self.grade = \"A\"\n",
    "        elif score >= 80.0:\n",
    "            self.grade = \"B\"\n",
    "        elif score >= 70.0:\n",
    "            self.grade = \"C\"\n",
    "        else:\n",
    "            self.grade = \"D\"\n",
    "            \n",
    "        Member.count += 1 \n",
    "        \n",
    "\n",
    "        \n",
    "    def display_grade(self):\n",
    "        print (\"%s 的等级是： %s\" %(self.name , self.grade))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "570a4f3b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "范淼 的等级是： C\n",
      "刘晓龙 的等级是： B\n",
      "陈蓓 的等级是： A\n",
      "孙华枭 的等级是： D\n"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':  \n",
    "    student_1 = Member('范淼', 70.5)\n",
    "    student_2 = Member('刘晓龙', 81.5)\n",
    "    student_3 = Member('陈蓓', 96)\n",
    "    student_4 = Member('孙华枭', 47.0)\n",
    "    \n",
    "    students = [student_1, student_2, student_3, student_4]\n",
    "    \n",
    "    for student in students:\n",
    "        student.display_grade()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71e9a892",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f46249b1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
